from flask import Blueprint, request
from flask_demo.entities import LogicWork
from flask_demo import app_database
logic_work_blue_print = Blueprint("logic_work_blue_print", __name__, url_prefix="/logic_work")


@logic_work_blue_print.route("/new", methods=["POST", ])
def post_logic_work_new():
    author_id = request.json.get("author_id")
    content = request.json.get("content")
    title = request.json.get("title")
    success = True
    new_logic_work = None
    try:
        new_logic_work = LogicWork(
            author_id=int(author_id),
            content=content,
            title=title
        )
        app_database.session.add(new_logic_work)
        app_database.session.commit()
    except:
        print("error: post_logic_work_new")
    return {
        "success": success,
        "data": {
            "logic_work_id": new_logic_work.logic_work_id if new_logic_work is not None else -1
        }
    }


@logic_work_blue_print.route("/update", methods=["post", ])
def post_logic_work_update():
    return {
        "ok": True
    }


@logic_work_blue_print.route("/all", methods=["get", ])
def get_logic_work_all():
    return {
        "ok": True,
        "dataList": []
    }


@logic_work_blue_print.route("/mine", methods=["get", ])
def get_logic_work_mine():
    return {
        "ok": True,
        "dataList": []
    }


@logic_work_blue_print.route("/delete", methods=["post", ])
def post_logic_work_delete():
    return {
        "ok": True,
    }


@logic_work_blue_print.route("/run", methods=["post", ])
def post_logic_work_run():
    return {
        "ok": True,
        "data": {

        }
    }
